﻿using System.Collections.Generic;
using Omniscient.Foundation.Data;
using Omniscient.Foundation.Data.ObjectQuery;
using Omniscient.TimeTracker.Data;
using Omniscient.TimeTracker.Data.Adapters.MySql;
using Omniscient.Foundation.ApplicationModel;

namespace Omniscient.TimeTracker.Server
{
    public class CategoryAdapterService : IEntityAdapter<Category>
    {
        private IEntityAdapter<Category> _adapter;

        public CategoryAdapterService()
        {
            _adapter = ApplicationManager.Current.ObjectContainer.Get<IEntityAdapter<Category>>();
        }

        #region IEntityAdapter<Category> Members

        public EntityList<Category> LoadAll()
        {
            if (_adapter == null) return null;
            return _adapter.LoadAll();
        }

        public EntityList<Category> LoadByForeignKey(string propertyName, System.Guid id)
        {
            if (_adapter == null) return null;
            return _adapter.LoadByForeignKey(propertyName, id);
        }

        public Category LoadByKey(System.Guid id)
        {
            if (_adapter == null) return null;
            return _adapter.LoadByKey(id);
        }

        public EntityList<Category> LoadByObjectQuery(OQuery<Category> query)
        {
            if (_adapter == null) return null;
            return _adapter.LoadByObjectQuery(query);
        }

        public EntityList<Category> LoadByQuery(string queryName)
        {
            if (_adapter == null) return null;
            return _adapter.LoadByQuery(queryName);
        }

        public EntityList<Category> LoadByValueProperty(string propertyName, object value)
        {
            if (_adapter == null) return null;
            return _adapter.LoadByValueProperty(propertyName, value);
        }

        public void Save(IEnumerable<Category> entities)
        {
            if (_adapter == null) return;
            _adapter.Save(entities);
        }

        public void Save(Category entity)
        {
            if (_adapter == null) return;
            _adapter.Save(entity);
        }

        #endregion
    }
}
